package com.example.myapplication.slice.slice;

import baidu.AdvancedGeneral;
import com.example.myapplication.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Button;
import ohos.agp.components.Component;

import static baidu.AdvancedGeneral.advancedGeneral;

public class coldPageAbilitySlice extends AbilitySlice implements Component.ClickedListener{

    Button camera;
    Button saveBut1;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_cold_ability_main1);

        camera = (Button)findComponentById(ResourceTable.Id_camera);

        camera.setClickedListener(this);

        saveBut1 = (Button)findComponentById(ResourceTable.Id_saveBut1);

        saveBut1.setClickedListener(this);

        if (saveBut1 != null) {
            // 设置按钮点击事件监听器
            saveBut1.setClickedListener(new Component.ClickedListener() {
                @Override
                public void onClick(Component component) {
                    // 调用advancedGeneral方法
                    String result = AdvancedGeneral.advancedGeneral();
                    // 根据需要处理结果，比如更新UI或显示结果
                    // ...
                }
            });
        }

    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }

    @Override
    public void onClick(Component component) {
        if(component == camera){
            Intent i = new Intent();
            //意图中包含了要跳转的页面信息
            Operation operation = new Intent.OperationBuilder()
                    .withDeviceId("")//要跳转到哪个设备上，如果传递一个没有内容的字符串，表示跳转本机
                    .withBundleName("com.example.myapplication")//要跳转到哪个应用上，小括号里面可以写包名
                    .withAbilityName("com.example.myapplication.picturePageAbility")//要跳转的页面
                    .build();//将上面的三个信息进行打包到一个operation对象当中（点击build，按ctrl+Alt+v）
            i.setOperation(operation);//把打包之后的operation设置到意图里
            startAbility(i);//跳转页面
        }
    }
}
